#include <iostream>
using namespace std;
int main()
{
    int lottery[3][3];
    bool ifSee[10] = {};
   /*
    for(int i = 0; i<10; i++)
       cout <<boolalpha << ifSee[i] <<" ";
    */
    int line,col;
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cin >> lottery[i][j];
            if(lottery[i][j] == 0)
            {
                line = i;
                col = j;
            }
            else
                ifSee[lottery[i][j]] = true;
        }
    }
    for(int i = 1; i < 10; i++)
    {
        if(ifSee[i] == false)
        {
            lottery[line][col] = i;
            break;
        }
    }
    /*
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
            cout << lottery[i][j] << " ";
        cout << endl;
    }
    */
    for(int i = 0; i<3;i++)
    {
        cin >> line >> col;
        cout << lottery[line-1][col-1]<<endl;
    }
    int choice;
    int reward[] = {0,0,0,0,0,0,10000,36,720,360,80,252,108,72,54,180,72,180,119,36,306,1080,144,1800, 3600};
    int num;
    cin >> choice;
    switch(choice)
    {
        case 1:
        case 2:
        case 3:
            num = lottery[choice-1][0] + lottery[choice-1][1] + lottery[choice-1][2];
            break;
        case 4:
        case 5:
        case 6:
            num = lottery [0][choice-4] + lottery[1][choice-4] + lottery[2][choice-4];
            break;
         case 7:
            num = lottery[0][0] + (lottery[1]) [1] + lottery[2][2];
            break;
        case 8:
            num = lottery[0] [2] + lottery[1][1] + lottery[2][0];
            break;
    }
    cout << reward[num];
    
}